import 'package:flutter/material.dart';
import 'package:online_study/base/app_title.dart';
import 'package:online_study/mine/required/all_required_course.dart';
import 'package:online_study/theme/colors.dart';
import 'package:online_study/theme/size.dart';

//必修课程
class RequiredCoursePage extends StatefulWidget {
  @override
  _RequiredCoursePageState createState() => _RequiredCoursePageState();
}

class _RequiredCoursePageState extends State<RequiredCoursePage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  final tabs = ["全部", "学习未完成", "学习完成", "训练未达标", "训练已达标"];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(color: ThemeColor.color333333),
        titleSpacing: 0,
        backgroundColor: ThemeColor.colorWhite,
        elevation: ThemeSize.appElevation,
        title: AppTitle("必修课程"),
      ),
      body: Column(
        children: [
          Container(
            height: ThemeSize.height34,
            child: _buildTab(),
          ),
          Divider(height: ThemeSize.width1),
          Expanded(child: _buildTableBarView())
        ],
      ),
    );
  }

  Widget _buildTab() {
    return TabBar(
      onTap: (tab) {
        print(tab);
      },
      labelStyle:
          TextStyle(fontSize: ThemeSize.sp14, fontWeight: FontWeight.bold),
      unselectedLabelStyle: TextStyle(fontSize: ThemeSize.sp13),
      isScrollable: true,
      labelColor: ThemeColor.color333333,
      unselectedLabelColor: ThemeColor.color808080,
      controller: _tabController,
      indicatorWeight: ThemeSize.height2,
      // indicatorPadding: EdgeInsets.symmetric(horizontal: ThemeSize.width8),
      indicatorColor: ThemeColor.color1485EE,
      tabs: tabs.map((e) => Tab(text: e)).toList(),
    );
  }

  Widget _buildTableBarView() {
    return TabBarView(
        physics: NeverScrollableScrollPhysics(),
        controller: _tabController,
        children: [
          AllRequiredCourse(),
          AllRequiredCourse(),
          AllRequiredCourse(),
          AllRequiredCourse(),
          AllRequiredCourse(),
        ]);
  }
}
